package com.atguigu.gmall;

import com.atguigu.gmall.common.constant.RedisConst;
import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

@SpringBootApplication//如果扫描不到持久层mapper,持久层对象无法产生, ioc没有bean对象
@EnableDiscoveryClient
public class ProductApp implements CommandLineRunner {
    public static void main(String[] args) {
        SpringApplication.run(ProductApp.class,args);
    }

    @Autowired
    private RedissonClient redissonClient;
    /**
     * 布隆过滤器初始化,springboot应用启动后执行,并且只会执行一次
     * @param args
     * @throws Exception
     */
    @Override
    public void run(String... args) throws Exception {
        System.out.println("布隆过滤器初始化,springboot应用启动后执行,并且只会执行一次");
        //存商品id
        //1.创建布隆过滤器
        RBloomFilter<Long> bloomFilter = redissonClient.getBloomFilter(RedisConst.SKU_BLOOM_FILTER);
        //2.为布隆过滤器指定数据规模,以及误判率
        bloomFilter.tryInit(100000,0.03);
    }
}
